﻿using StockholmsStad.Data.Entity;

namespace StockholmsStad.Data.ContractFactory
{
    /// <summary>
    /// Konvertering befintligt dataobjekt till kontraktsobjekt
    /// </summary>
    internal class CoupleFactory
    {
        public Couple CreateEntityObject(Runtime.Serialization.DataContract.Couple couple)
        {
            PersonFactory personFactory = FactoryAgent.GetPersonFactory();

            var entityCouple = new Couple
                                   {
                                       Person1 = personFactory.CreateEntityObject(couple.Person1),
                                       Person2 = personFactory.CreateEntityObject(couple.Person2),
                                   };

            if (couple.CoupleId.HasValue)
                entityCouple.CoupleId = couple.CoupleId.Value;

            if (couple.ContactPerson != null)
                entityCouple.ContactPerson = personFactory.CreateEntityObject(couple.ContactPerson);

            return entityCouple;
        }

        public Runtime.Serialization.DataContract.Couple CreateContractObject(Couple couple)
        {
            PersonFactory personFactory = FactoryAgent.GetPersonFactory();

            var contractCouple = new Runtime.Serialization.DataContract.Couple
                                     {
                                         Person1 = personFactory.CreateContractObject(couple.Person1),
                                         Person2 = personFactory.CreateContractObject(couple.Person2),
                                         CoupleId = couple.CoupleId,
                                         ContactPerson = personFactory.CreateContractContact(couple.ContactPerson),
                                     };

            return contractCouple;
        }
    }
}